//
//  SISSUserAccount.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/22.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSUserAccount.h"


static NSString * const userAccountKey = @"userAccountKey";
@implementation SISSUserAccount

+ (instancetype)shared {
    
    static SISSUserAccount *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
        [instance readUserAccountInfo];
    });
    return instance;
}

// 异常处理
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {

//    if([key isEqualToString:@"id"]) {
//        self.sa_id = value;
//    }
}


- (void)saveUserAcountInfoWithDict:(NSDictionary *)dict {
    
    // 先用字典给模型属性赋值
    [self setValuesForKeysWithDictionary:dict];
    
    // 模型转字典
//    NSDictionary *userAccountDict = [self dictionaryWithValuesForKeys:@[@"userName", @"sobId", @"token_type", @"access_token", @"soId", @"saId", @"spId"]];
    [[NSUserDefaults standardUserDefaults] setObject:dict forKey:userAccountKey];
}

- (void)readUserAccountInfo {
    
    // 从缓存中读取字典
    NSDictionary *userAccountDict = [[NSUserDefaults standardUserDefaults] objectForKey:userAccountKey];
    
    // 用字典给模型属性赋值
    [self setValuesForKeysWithDictionary:userAccountDict];
}

@end
